﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PocketCargo
{
    public partial class SearchDianHuaForm : Form
    {
        public SearchDianHuaForm()
        {
            InitializeComponent();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Close();
        }
        
        private void SearchDianHuaForm_Load(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.Focus();
        }

        private void DoSearchDianHua1()
        {
            //String sqlCommand = "select top 100 * from msg";
            String sqlCommand = "";

            String DianhuaHaoma = "";  //关键字
            DianhuaHaoma = textBox1.Text;
            DianhuaHaoma = DianhuaHaoma.Trim();  //清除开头和末尾空白
            if (DianhuaHaoma.Length > 0)
            {
                sqlCommand += " where CHARINDEX('" + DianhuaHaoma + "', tel) <> 0";
            }
            else
            {
                MessageBox.Show("请输入正确的电话号码!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return;
            }

            //获取发布人信息
            //sqlCommand += " and msg_table.masterid = master_table.masterid";

            //分页
            //sqlCommand += " and id not in ( %s )";

            //排序
            //sqlCommand += " order by msgtime desc";

            SearchResultForm form = new SearchResultForm(sqlCommand);
            DialogResult result = form.ShowDialog();
            if (result == DialogResult.OK)
            {
            }
            else if (result == DialogResult.Cancel)
            {
            }
        }

        private void DoSearchDianHua2()
        {
            //String sqlCommand = "select top 100 * from msg";
            String sqlCommand = "";

            String DianhuaHaoma = "";  //关键字
            DianhuaHaoma = textBox1.Text;
            DianhuaHaoma = DianhuaHaoma.Trim();  //清除开头和末尾空白
            if (DianhuaHaoma.Length > 0)
            {
                sqlCommand += " where CHARINDEX('" + DianhuaHaoma + "', msg) <> 0";
            }
            else
            {
                MessageBox.Show("请输入正确的电话号码!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return;
            }

            //获取发布人信息
            //sqlCommand += " and msg_table.masterid = master_table.masterid";

            //分页
            //sqlCommand += " and id not in ( %s )";

            //排序
            //sqlCommand += " order by msgtime desc";

            SearchResultForm form = new SearchResultForm(sqlCommand);
            DialogResult result = form.ShowDialog();
            if (result == DialogResult.OK)
            {
            }
            else if (result == DialogResult.Cancel)
            {
            }
        }

        private void button58_Click(object sender, EventArgs e)
        {
            textBox1.Text += button58.Text;
        }

        private void button56_Click(object sender, EventArgs e)
        {
            textBox1.Text += button56.Text;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            textBox1.Text += button11.Text;
        }

        private void button21_Click(object sender, EventArgs e)
        {
            textBox1.Text += button21.Text;
        }

        private void button12_Click(object sender, EventArgs e)
        {
            textBox1.Text += button12.Text;
        }

        private void button13_Click(object sender, EventArgs e)
        {
            textBox1.Text += button13.Text;
        }

        private void button54_Click(object sender, EventArgs e)
        {
            textBox1.Text += button54.Text;
        }

        private void button22_Click(object sender, EventArgs e)
        {
            textBox1.Text += button22.Text;
        }

        private void button24_Click(object sender, EventArgs e)
        {
            textBox1.Text += button24.Text;
        }

        private void button23_Click(object sender, EventArgs e)
        {
            textBox1.Text += button23.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text += button2.Text;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox1.Focus();
            textBox1.SelectionStart = textBox1.TextLength;
            textBox1.SelectionLength = 0;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 12)
            {
                MessageBox.Show("电话号码位数过多,请不要超过12个字符!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return;
            }
            DoSearchDianHua1();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 12)
            {
                MessageBox.Show("电话号码位数过多,请不要超过12个字符!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return;
            }
            DoSearchDianHua2();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string text = textBox1.Text;
            if (text.Length > 0)
            {
                string text2 = text.Substring(0, text.Length - 1);
                textBox1.Text = text2;
            }
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("请先按'搜索一'按钮进行搜索,如果没有记录,则可以再按'搜索二'按钮试试看!\n鉴于有些电话中间会有'－'符号,建议您不必输入电话区号。", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            return;
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.Focus();
        }
     
    }
}

